
<extend name="Public/layout"/>
<block name="head">
<link rel="stylesheet" href="__PUBLIC__css/short-comment.css">
<style type="text/css">
.footer{
  display: none;
}
</style>
</block>
    
   <block name="main">
      <div class="container">
        <div class="short-one">
          <div class="one-title">
            <h4>请选择您对平台的评价</h4>
          </div>
          <a class="one-have">
            <p>您已选择 
              <switch name="colligate" >
                <case value="1" break="1">放心投</case>
                <case value="2">可以投 </case>
                <case value="3">谨慎投 </case>
                <case value="4">不要投 </case
                  ></switch>，点击更改 > 
            </p>
          </a>
        </div>
        <div class="short-two">
          <div class="two-title">
            <h4>请根据您的投资体验 针对平台做出安全性评价</h4>
          </div>
          <div class="label">
            <ul class="label-comment clearfix">
              <li>
                <div <if condition='in_array("提现慢",$info[tag])'> class="label-active"</if> >
                  <p>提现慢</p>
                </div>
              </li>
              <li>
                <div <if condition='in_array("服务好",$info[tag])'> class="label-active"</if>>
                  <p>服务好</p>
                </div>
              </li>
              <li>
                <div <if condition='in_array("回复慢",$info[tag])'> class="label-active"</if>>
                  <p>回复慢</p>
                </div>
              </li>
              <li>
                <div <if condition='in_array("有手续费",$info[tag])'> class="label-active"</if>>
                  <p>有手续费</p>
                </div>
              </li>
              <li>
                <div <if condition='in_array("不透明",$info[tag])'> class="label-active"</if>>
                  <p>不透明</p>
                </div>
              </li>
              <li>
                <div <if condition='in_array("收益高",$info[tag])'> class="label-active"</if>>
                  <p>收益高</p>
                </div>
              </li>
              <li>
                <div <if condition='in_array("收益低",$info[tag])'> class="label-active"</if>>
                  <p>收益低</p>
                </div>
              </li>
              <li class="add-label-li">
                <div class="add-label">
                  <p>+新标签</p>
                </div>
              </li>
            </ul>
          </div>
          <div class="short-comment" id="wordCounta">
            <textarea class="comment-textarea" cols="5" type="text" maxlength="500" placeholder="您已实名认证，请根据您的情况作出实际评价，不造谣，不夸大。一旦发现评论出现恶意造谣等虚假信息，将对评论本人进行曝光，封号处理，如有违法，将提交公安机关处理。" ><if condition="$edit eq 1" >{$info.evaluate}</if></textarea>
            <span class="wordWrap">
            <var class="word">500</var>/ 500
            </span>
          </div>
        </div>
        
        <div class="submit" onclick="sub()">
          <p>提交</p>
        </div>

      </div>
      <!-- 弹出层 -->
   <div class="popup" <notempty name="colligate">style="display:none"</notempty>>
        <div class="popup-com">
          <div class="popup-title">
            <p>请选择您对平台的评价</p>
          </div>
          <div class="popup-con">
            <ul class="clearfix" id="tag">
              <li>
                <div class="unchecked one <if condition='$colligate eq 1'> active</if>" attr_id='1'>
                  <p>放心投</p>
                </div>
              </li>
              <li>
                <div class="unchecked two <if condition='$colligate eq 2'> active</if>"  attr_id='2'>
                  <p>可以投</p>
                </div>
              </li>
              <li>
                <div class="unchecked three <if condition='$colligate eq 3'> active</if>"  attr_id='3'>
                  <p>谨慎投</p>
                </div>
              </li>
              <li>
                <div class="unchecked four <if condition='$colligate eq 4'> active</if>"   attr_id='4'>
                  <p>不要投</p>
                </div>
              </li>
            </ul>
            <ul class="clearfix have">
              <li>
                <div class="unchecked <if condition='$is_invest eq 1'> haveactive</if>" attr_id='1'>
                  <p>已投资</p>
                </div>
              </li>
              <li>
                <div class="unchecked <if condition='$is_invest eq 0'> haveactive</if>"   attr_id='0'>
                  <p>未投资</p>
                </div>
              </li>
            </ul>
          </div>
<!--           <div class="popup-check">
            <div class="p-check <if condition='$is_invest eq 1'> p-active</if>" <if condition='$is_invest eq 1'>attr_check="1"<else/>attr_check="0"</if>></div>
            <p>未投资</p>  
          </div> -->
          <div class="popup-submit">
            <p>下一步</p>
          </div>
        </div>
      </div>
      </div>
      <!-- 新增标签弹窗 -->
      <div class="add-new">
      <div class="label-new">
          <div class="label-title">
            <h4>添加新标签并确认</h4>
            <p class="label-cancle">取消</p>
          </div>
          <div class="label-con">
            <input type="text" placeholder="请输入新标签(最多可输入四个文字)" >
          </div>
          <div class="label-add" onclick = 'addLabelLength(this)'>
            <p>确定</p>
          </div>
        </div>
      </div>

    </block>
    <block name="js">
      <script type="text/javascript">
       function addLabelLength(obj){
        var re=/[\u4E00-\u9FA5]/g;
        var addText = $('.label-con input').val();
        if(addText){
        if(re.test(addText)){
              if(addText.match(re).length> 4){
              layer.open({
                  content: '最多输入四个文字！'
                  ,skin: 'msg'
                  ,time: 2 //2秒后自动关闭
                });
             $('.label-con input').val(addText.substr(0,4));
            }else{
                $('.add-new').css('display','none');
                var labelNew  = $('.label-con > input').val();
                var newLi ='<li><div class="label-active addLabel"><p></p><div></li>'
                $('.add-label-li').before(newLi);
                var newP = $(".label-comment >li:nth-last-child(2) > div > p");
                newP[0].innerHTML = labelNew;
                $('.label-con > input').val('');

                $('.addLabel').each(function(i,v){

                
                    $(v).click(function(){
                      
                        if($(v).hasClass('label-active')){
                          $(v).removeClass('label-active');
                        }else{
                            $(v).addClass('label-active');
                          
                          
                        }
                    });
               
              
              })
            }
          }else{
              layer.open({
                  content: '只能输入中文汉字！'
                  ,skin: 'msg'
                  ,time: 2 //2秒后自动关闭
                });
              $('.label-con input').val('');
            }
        }else{
          layer.open({
            content: '请输入标签！'
            ,skin: 'msg'
            ,time: 2 //2秒后自动关闭
          });
          $('.label-con input').val('');
        }
        
        
        
        
       }
       $('.one-have').click(function() {
          $('.popup').css('display','block');
        });
          // 点击评价
          $('#tag > li > div').each(function(index, v) {
            $(v).click(function(){
              $('#tag > li > div').each(function(index, v){
                $(v).removeClass('active')
              });
              $(v).addClass('active');
            });
          });
          $('.have > li > div').each(function(index, v) {
            $(v).click(function(){
              $('.have > li > div').each(function(index, v){
                $(v).removeClass('haveactive')
              });
              $(v).addClass('haveactive');
            });
          });
        $('.popup-submit').click(function() {
          
          var  text ='',temp = 0;
          $('#tag > li > div').each(function(index, v) {
            if($(v).hasClass('active')){
              temp +=1;
            }
            $('.one-have > p')[0].innerHTML = '您已选择'+text+'，点击更改 >';
          });
          if(temp>1){
            layer.open({
              content: '最多只能选择一个评价！'
              ,skin: 'msg'
              ,time: 2 //2秒后自动关闭
            });
          }else if(temp==0){
             layer.open({
              content: '必须要选择一个评价！'
              ,skin: 'msg'
              ,time: 2 //2秒后自动关闭
            });
          }else{
                //提交综合评价
              var colligate = $('#tag > li > .active').attr('attr_id');
              var platform_id = '{$_GET["id"]}';
              var is_invest = $('.have > li > .haveactive').attr('attr_id');
              $.post('/Home/circle/grade',{
                  platform_id:platform_id,
                  colligate:colligate,
                  is_invest:is_invest
              },function(res){
                    if(res.err!=0){
                           layer.open({
                              content:"您未改变评价！"
                              ,skin: 'msg'
                              ,time: 2 //2秒后自动关闭
                            });
                          
                    }

                        $('.popup').css('display','none');
                        $('#tag > li > div').each(function(index, v) {
                            if($(v).hasClass('active')){
                                text += $(v).children('0').prevObject["0"].innerText;
                            }
                            $('.one-have > p')[0].innerHTML = '您已选择'+text+'，点击更改 >';
                        });
              })
            
           
        }
        });
        // 是否已投资
        $('.p-check').click(function() {
          if ($('.p-check').hasClass('p-active')) {
            $('.p-check').removeClass('p-active');
            $('.p-check').attr('attr_check','0');
            $('.p-check~p').html('未投资');
          }else{
            $('.p-check').addClass('p-active');
            $('.p-check').attr('attr_check','1');
            $('.p-check~p').html('已投资');
          };
        });

        $('.add-label').click(function() {
          
          if($('.addLabel').length>=3){
            layer.open({
              content: '最多只能新增三个标签！'
              ,skin: 'msg'
              ,time: 2 //2秒后自动关闭
            });
          }else{
            $('.add-new').css('display','block');
          }
        });
        // 取消新增
        $('.label-cancle').click(function(){
          $('.add-new').css('display','none');
          $('.label-con > input').val('');
        })
        // 确认新增
  //       $('.label-add').click(function(){
  //         console.log(1);
  //         var addText = $('.label-con input').val();
  //         if(addText){
            
  //           $('.add-new').css('display','none');
  //           var labelNew  = $('.label-con > input').val();
  //           var newLi ='<li><div class="label-active addLabel"><p></p><div></li>'
  //           $('.add-label-li').before(newLi);
  //           var newP = $(".label-comment >li:nth-last-child(2) > div > p");
  //           newP[0].innerHTML = labelNew;
  //           $('.label-con > input').val('');

  //           $('.addLabel').each(function(i,v){

            
  //               $(v).click(function(){
                  
  //                   if($(v).hasClass('label-active')){
  //                     $(v).removeClass('label-active');
  //                   }else{
  //                       $(v).addClass('label-active');
                      
                      
  //                   }

                    
                    
  //               });
           
          
  //         }) 
          
  //       }else{
  //         layer.open({
  //   content: '请输入标签！'
  //   ,skin: 'msg'
  //   ,time: 2 //2秒后自动关闭
  // });
  //       }
          
          
        // });
  
      </script>

       <script type="text/javascript">
          $('#tag > li > div').each(function(index, v) {
        $(v).click(function(){
            $('#tag > li > div').removeClass('active');
            $(v).addClass('active');
        });
      });


         var label = $(".label-comment >li> div");
         
          $(label).each(function(i,v){

            if($(v).attr('class')!='add-label'){
                $(v).click(function(){
                  
                    if($(v).hasClass('label-active')){
                      $(v).removeClass('label-active');
                    }else{
                        $(v).addClass('label-active');
                      
                      
                    }

                    
                    
                });
            }
          
          })  

    $(function(){
        var wordCount = $("#wordCounta"),
            textArea = wordCount.find("textarea"),
            word = wordCount.find(".word");
        statInputNum(textArea,word);
    });
    function statInputNum(textArea,numItem) {
        var max = numItem.text(),
            curLength;
        textArea[0].setAttribute("maxlength", max);
        curLength = textArea.val().length;
        numItem.text(max - curLength);
        textArea.on('input propertychange', function () {
            var _value = $(this).val().replace(/\n/gi,"");
            numItem.text(max - _value.length);
        });
    }

    function sub(){
      var l_len = $('.label-active').length;
      if(l_len==0){
          layer.open({
            content: '您还未选择标签！'
            ,skin: 'msg'
            ,time: 2 //2秒后自动关闭
          });
          return;
      }
      var t_text = $('.comment-textarea').val();
      if(!t_text){
        layer.open({
            content: '您还未进行评价！'
            ,skin: 'msg'
            ,time: 2 //2秒后自动关闭
          });
          return;
      }
      var tag = [];
      $('.label-active').each(function(i,v){
        tag.push($(v).find('p').text());
      })
      var content = $('.comment-textarea').val();
      var platform_id ="{$_GET['id']}";
      var edit = "{$edit}";
      if(edit){
        var info_id = "{$_GET['info_id']}";
        postdata = {tag:tag,evaluate:content, platform_id:platform_id,edit:edit,info_id:info_id};
      }else{
        postdata = {tag:tag,evaluate:content, platform_id:platform_id};
      }
      $.post("/Home/circle/short_commentary",postdata,function(res){
        var edit = "{$edit}";
        if(edit){
          layer.open({
              content:res.msg
              ,skin: 'msg'
              ,time: 2 //2秒后自动关闭
              ,end:function(){history.go(-1)}
            });
        }else{
          layer.open({
              content:res.msg
              ,skin: 'msg'
              ,time: 2 //2秒后自动关闭
              ,end:function(){location.href="/Home/circle/circle_info/id/"+platform_id}
            });
        }
          
        
        
      })
      //console.log(tag)
    }

 </script>  
</block>